import $ from 'jquery';
import DesignTableAction from '@/components/hhd/design/DesignTable/DesignTableAction';

const layoutActions = [];

export default class {
  constructor(root, formDefinition, config) {
    this.root = root;
    this.formDefinition = formDefinition;
    this.config = config;
  }

  bind() {
    this.unbind();
    let tables = $(this.root).find('.design-table');
    if (!tables || !tables.length) return;
    for (let i = 0; i < tables.length; i++) {
      let a = new DesignTableAction();
      layoutActions.push(a);
      a.bind(tables[i], this.config);
    }
    return this;
  }

  unbind() {
    layoutActions.forEach(a => a.destory && a.destory());
    layoutActions.splice(0, layoutActions.length);
  }
}